//
//  SortCollectionViewCell.m
//  TasteEnjoy
//
//  Created by XuRui on 16/4/19.
//  Copyright © 2016年 XuRui. All rights reserved.
//

#import "SortCollectionViewCell.h"

@interface SortCollectionViewCell ()

@property (nonatomic, retain) BaseImageView *imgTubiao; /**< 图标 */
@property (nonatomic, retain) BaseLabel *labelname; /**< 图标名字 */

@end

@implementation SortCollectionViewCell

#pragma mark - ------------ 内存管理 ---------------
- (void)dealloc
{
    [_imgTubiao release];
    [_labelname release];
    [_model release];
  
    [super dealloc];
    
}

#pragma mark - ------------ 初始化控件 ---------------
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubViews];
      
    }
    return self;
}

#pragma mark - ------------ 设置大小 ---------------
- (void)createSubViews
{
    

    self.imgTubiao = [[BaseImageView alloc]init];
    [self.contentView addSubview:_imgTubiao];

    
    self.labelname = [[BaseLabel alloc]init];
    [self.contentView addSubview:_labelname];
    _labelname.font = [UIFont systemFontOfSize:13];
/** 夜间 */
    _labelname.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor lightGrayColor]);
    
    [_imgTubiao release];
    [_labelname release];
   
    
}

#pragma mark - ------------ 约束 赋大小 ---------------
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
  
    _labelname.translatesAutoresizingMaskIntoConstraints = NO;
    _imgTubiao.translatesAutoresizingMaskIntoConstraints = NO;
    
    
   
    
    //距离content 上左 右 为0 下距离label 5
    [_imgTubiao mas_makeConstraints:^(MASConstraintMaker *make) {
   
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(23);
        make.right.equalTo(self.contentView).offset(-23);
        make.bottom.mas_equalTo(_labelname.mas_top).offset(-5);
        
     }];
    
    //距离左右下 为 0 高度 是整个content 1/4
    [_labelname mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.bottom.equalTo(self.contentView).offset(-10);
        make.left.mas_equalTo(self.contentView).offset(10);
        make.height.mas_equalTo(self.contentView.frame.size.height * 1 /4);
    }];

}

#pragma mark - ------------ 重写 赋值 mode set  ---------------
- (void)setModel:(EnjoyModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [_imgTubiao sd_setImageWithURL:[NSURL URLWithString:model.img_url] placeholderImage:PLACEHOLDER];
    _labelname.text = model.title;
    _labelname.textAlignment = NSTextAlignmentCenter;
    

}



@end
